package com.zzq.demo.retry;

import com.github.rholder.retry.*;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author: zhaoziqian
 * @description: TODO
 * @date: 2019/10/21 9:35 下午
 **/
@Component
public class MyRetryerBuilder {

    public Retryer build() {
        return RetryerBuilder.<Model>newBuilder()
                .retryIfExceptionOfType(Exception.class)
                .retryIfRuntimeException()
                //
                .withWaitStrategy(WaitStrategies.fibonacciWait(100, 5, TimeUnit.MINUTES))
                .withStopStrategy(StopStrategies.neverStop())
                //默认的阻塞策略：线程睡眠
//                .withBlockStrategy(BlockStrategies.threadSleepStrategy())
                //自定义阻塞策略：自旋锁
                .withBlockStrategy(new SpinBlockStrategy())
                //自定义重试监听器
                .withRetryListener(new RetryLogListener())
                // 重试次数
//                .withStopStrategy(StopStrategies.stopAfterAttempt(20))
                .build();
    }
}
